package 力扣._100031_计算K置位下标对应元素的和;

import java.util.*;

public class Solution {
    public int sumIndicesWithKSetBits(List<Integer> nums, int k) {
        int total = 0;
        for (int i = 0; i < nums.size(); i++) {
            int t = nums.get(i);
            int index = i;
            int zhi = 0;
            while (index > 0) {
                if (index % 2 == 1)
                    zhi++;
                index /= 2;
            }
            if (zhi == k)
                total += t;
        }
        return total;
    }
}
